import {
    totalConfig,
    propName
} from 'server/config/templateConfig';
import utils from 'server/core/utils';

let mazeConfig = totalConfig.maze;
let cardsConfig = totalConfig.card;
//地图信息
class MazeInfo {
    static getInstance() {
        if (!MazeInfo.instance) {
            MazeInfo.instance = new MazeInfo();
        }
        return MazeInfo.instance;
    }

    create(originMazeInfo) {
        originMazeInfo = originMazeInfo || {};
        let data = {
            type: 1, //1怪物牌,2资源牌
            indexId: originMazeInfo.indexId || 1,
            mazeId: originMazeInfo.mazeId || 180001,
            zoneId: originMazeInfo.zoneId || 1,
            cards: originMazeInfo.cards,
        }

        if (!originMazeInfo.cards) {
            this.mazeReset(data)
        }
        return data;
    }

    mazeReset(mazeInfos) {
        let cards = [];
        mazeInfos.indexId += 1;
        for (let i = 0; i < 4; i++) {
            let card = this.getCard(mazeInfos);
            cards.push(card);
        }
        mazeInfos.cards = cards;
    }

    getCard(mazeInfos) {
        let mazeId = mazeInfos.mazeId;
        let zoneId = mazeInfos.zoneId;
        let zonesInfo = mazeConfig[mazeId].zones[zoneId];
        let randNumber = Math.random() * 100;
        if (randNumber < 60) {
            let monsterId = utils.getOneFromArray(zonesInfo.monsters);

            let card = {
                indexId: mazeInfos.indexId,
                type: 2,
                id: monsterId,
            };
            mazeInfos.indexId += 1;
            return card;
        } else {
            let cardId = utils.getOneFromArray(zonesInfo.cards);
            let card = {
                indexId: mazeInfos.indexId,
                type: 1,
                id: cardId,
            };
            mazeInfos.indexId += 1;
            return card;
        }
    }

    getMonsterCard(mazeInfos) {
        let mazeId = mazeInfos.mazeId;
        let zoneId = mazeInfos.zoneId;
        let zonesInfo = mazeConfig[mazeId].zones[zoneId];

        let monsterId = utils.getOneFromArray(zonesInfo.monsters);
        mazeInfos.monsterCardsIndexId += 1;
        let card = {
            indexId: mazeInfos.monsterCardsIndexId,
            type: 2,
            id: monsterId,
        };

        return card;
    }
}

export default MazeInfo.getInstance();